package com.wego.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wego.common.base.impl.BaseServiceImpl;
import com.wego.common.bean.PageBean;
import com.wego.entity.domain.OrderItem;
import com.wego.entity.query.OrderItemQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.wego.mapper.OrderItemMapper;
import com.wego.service.OrderItemService;

import java.util.List;

@Service
public class OrderItemServiceImpl extends BaseServiceImpl<OrderItem> implements OrderItemService {

    @Autowired
    private OrderItemMapper orderItemMapper;

    @Override
    public PageBean<OrderItem> selectPage(OrderItemQuery orderItemQuery) {
        //设置分页信息
        Page<OrderItem> page = PageHelper.startPage(orderItemQuery.getPageNum(), orderItemQuery.getPageSize());
        //查询数据
        orderItemMapper.selectList(orderItemQuery);
        //将MyBatis提供的Page对象转换成我们自己的PageBean对象
        PageBean<OrderItem> pageBean = new PageBean<>(page);
        return pageBean;
    }

    @Override
    public List<OrderItem> selectOrderItemByOrderId(Long orderId) {
        OrderItemQuery orderItemQuery = OrderItemQuery.builder().orderId(orderId).build();
        List<OrderItem> orderItemList = orderItemMapper.selectList(orderItemQuery);
        return orderItemList;
    }

}
